
package com.hiwan.framework.servlet.tags;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

import com.hiwan.platform.util.BeanUtils;
import com.hiwan.system.cache.OrgCacheService;
import com.hiwan.system.service.dept.DeptService;

/**
 * 
 * Datetime   ： 2013-1-29 下午3:27:58<br>
 * Title      :  DictNameByCodeTag.java<br>
 * Description:  根据字典表的code获取name <br>
 * Copyright  :  Copyright (c) 2013<br>
 * Company    :  HIWAN<br>
 * @author zdm
 *
 */
public class OrgNameByIdTagSplit extends TagSupport {

	private static final long serialVersionUID = -7389543849788306702L;

	private JspWriter out;
	private String orgId;
	// 值：block 或 none
	private boolean showId = false;

	@Override
	public int doStartTag() {
		OrgCacheService orgService = BeanUtils.getBean("orgService", OrgCacheService.class);
		try {
			if (StringUtils.isEmpty(orgId)) {
				out.print("");
			} else {
				String orgName = orgService.getOrgName(orgId);

				if (StringUtils.isEmpty(orgName)) {
					DeptService deptService = BeanUtils.getBean("deptService", DeptService.class);
					orgName = deptService.getDeptName(orgId);
				}
				
				if(orgName.equals("江苏省分行"))
				{
					orgName = "全省";
				}
				else if(orgName.contains("市分行"))
				{
					orgName = orgName.replace("市分行", "");
				}
				
				out = this.pageContext.getOut();
				if (showId) {
					out.print(orgName + "(" + orgId + ")");
				} else {
					out.print(orgName);
				}
			}
		} catch (Exception e) {
		}
		return Tag.EVAL_PAGE;
	}

	public JspWriter getOut() {
		return out;
	}

	public void setOut(JspWriter out) {
		this.out = out;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public boolean getShowId() {
		return showId;
	}

	public void setShowId(boolean showId) {
		this.showId = showId;
	}

}